/**
 * 11. Container With Most Water
 * https://leetcode.com/problems/container-with-most-water/
 */
package lc11;

public class Main {
  public static void main(String[] args) {
    int[] height = {1,8,6,2,5,4,8,3,7};
    int maxArea = new Solution().maxArea(height);
    System.out.println(maxArea);
  }
}

class Solution {
  public int maxArea(int[] height) {
    int left = 0, right = height.length - 1;
    int maxArea = (right - left) * Math.min(height[left], height[right]);
    while (left < right) {
      if (height[left] < height[right]) {
        left++;
      } else {
        right--;
      }
      maxArea = Math.max(maxArea, (right - left) * Math.min(height[left], height[right]));
    }
    return maxArea;
  }
}
